package cn.edu.sjtu.se.peakfactory.service.impls;

import java.util.ArrayList;
import java.util.List;

import cn.edu.sjtu.se.peakfactory.dao.bean.Brand;
import cn.edu.sjtu.se.peakfactory.dao.interfaces.BrandDAO;
import cn.edu.sjtu.se.peakfactory.service.bean.BrandVB;
import cn.edu.sjtu.se.peakfactory.service.interfaces.BrandService;

public class BrandServiceImpl implements BrandService {
	private BrandDAO brandDAO;

	public void setBrandDAO(BrandDAO brandDAO) {
		this.brandDAO = brandDAO;
	}
	
	@Override
	public List<BrandVB> searchBrandByName(String brandName){
		List<Brand> brands = brandDAO.searchBrandByName(brandName);
		List<BrandVB> result = new ArrayList<BrandVB>();
		for (Brand b : brands) {
			result.add(new BrandVB(b));
		}
		return result;
	}
	
	@Override
	public List<BrandVB> getAllBrands(){
		List<Brand> brands = brandDAO.findByHql("from Brand", null);
		List<BrandVB> result = new ArrayList<BrandVB>();
		for (Brand b : brands) {
			result.add(new BrandVB(b));
		}
		return result;
	}
}
